﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Buddy.Samples
{
    static partial class Program
    {
        static void Samples_UsingPipe()
        {
            // one can use Pipe extension method for programming in a functional style (like |> in F#)
            // but another usage I have found for it - and I use it frequently - is when you need an
            // extension method but you do not like to define a separate one because it would be used
            // in very few places. In these cases Pipe comes in very handy.

            //1
            Console.WriteLine("press esc if you do not like to continue; or any other key to continue");
            var escPressed = Console.ReadKey().Pipe(key => key.Key == ConsoleKey.Escape);
            if (escPressed) Environment.Exit(0);
            else Console.WriteLine();

            //2
            double degree = 90d;
            double radian = degree.Pipe(d => Math.PI * d / 180d);
            Console.WriteLine("{0} degree == {1} radian", degree, radian);

            //3
            var facebookAccount = new { Deactivated = true };
            var happiness = facebookAccount.Pipe(facunt => facunt.Deactivated ? "100%" : @":\");
            Console.WriteLine("user happiness = {0}", happiness);

            Console.WriteLine("press any key to continue ...");
            Console.ReadKey();
        }
    }
}
